<template>
	<view class="message-container">
		<!-- 顶部导航栏 -->
		<view class="nav-bar">
			<text class="title">消息中心</text>
		</view>
		
		<!-- 消息列表 -->
		<scroll-view scroll-y class="message-list">
			<view 
				class="message-item" 
				v-for="(item, index) in messageList" 
				:key="index"
				@click="navigateToChat(item)"
			>
				<image class="avatar" :src="item.avatar" mode="aspectFill"></image>
				<view class="content">
					<view class="top-line">
						<text class="name">{{ item.name }}</text>
						<text class="time">{{ item.lastTime }}</text>
					</view>
					<view class="bottom-line">
						<text class="last-message">{{ item.lastMessage }}</text>
						<view class="unread" v-if="item.unreadCount > 0">{{ item.unreadCount }}</view>
					</view>
				</view>
			</view>
		</scroll-view>
		
		<!-- 底部导航栏 -->
		<!-- <tabbarVue tabIndex=3></tabbarVue> -->
	</view>
</template>

<script>
import tabbarVue from '../../components/tabbar.vue'

export default {
	components: {
		tabbarVue
	},
	data() {
		return {
			messageList: [
				{
					id: '1',
					name: '活动客服',
					avatar: 'https://202231117.oss-cn-beijing.aliyuncs.com/女性客服1.png',
					lastMessage: '好的，我明白了。请问您还有其他问题吗？',
					lastTime: '12:30',
					unreadCount: 2
				},
				{
					id: '2',
					name: '会员客服',
					avatar: 'https://202231117.oss-cn-beijing.aliyuncs.com/男性客服1.png',
					lastMessage: '您的会员特权已经开通，请查收',
					lastTime: '昨天',
					unreadCount: 0
				},
				{
					id: '3',
					name: '系统客服',
					avatar: 'https://202231117.oss-cn-beijing.aliyuncs.com/女性客服1.png',
					lastMessage: '欢迎使用我们的服务，请问有什么可以帮您？',
					lastTime: '周一',
					unreadCount: 1
				}
			]
		}
	},
	methods: {
		navigateToChat(item) {
			uni.navigateTo({
				url: `./serviceChat?id=${item.id}&name=${item.name}`
			})
		}
	}
}
</script>

<style lang="scss">
// 定义混入
@mixin text-ellipsis {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.message-container {
	min-height: 100vh;
	background: #f8f9fa;
	display: flex;
	flex-direction: column;
	
	.nav-bar {
		height: 88rpx;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0 30rpx;
		box-shadow: 0 2rpx 10rpx rgba(0,0,0,0.05);
		
		.title {
			font-size: 32rpx;
			font-weight: 500;
			color: #333;
		}
	}
	
	.message-list {
		flex: 1;
		padding: 20rpx 0;
		
		.message-item {
			display: flex;
			align-items: center;
			padding: 20rpx 30rpx;
			background: #fff;
			margin-bottom: 20rpx;
			
			.avatar {
				width: 88rpx;
				height: 88rpx;
				border-radius: 50%;
				margin-right: 24rpx;
				flex-shrink: 0;
			}
			
			.content {
				flex: 1;
				min-width: 0; // 防止文本溢出
				
				.top-line {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 8rpx;
					
					.name {
						font-size: 32rpx;
						font-weight: 500;
						color: #333;
					}
					
					.time {
						font-size: 24rpx;
						color: #999;
						margin-left: 20rpx;
						flex-shrink: 0;
					}
				}
				
				.bottom-line {
					display: flex;
					justify-content: space-between;
					align-items: center;
					
					.last-message {
						flex: 1;
						font-size: 28rpx;
						color: #666;
						@include text-ellipsis;
						margin-right: 20rpx;
					}
					
					.unread {
						min-width: 36rpx;
						height: 36rpx;
						padding: 0 10rpx;
						background: #ff6b6b;
						border-radius: 18rpx;
						color: #fff;
						font-size: 24rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						flex-shrink: 0;
					}
				}
			}
			
			&:active {
				background: #f8f9fa;
			}
		}
	}
}
</style>
